package org.jeecg.service.service;

import org.jeecg.domain.Goods;
import org.jeecg.domain.History;
import org.jeecg.mapper.HistoryMapper;
import org.jeecg.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public List<Goods> getHistory(String username) {
        List<Goods> goodsByUsername = historyMapper.getGoodsByUsername(username);
        return goodsByUsername;
//        return null;
    }

    @Override
    public Boolean addHistory(String username, String goodId) {
        UUID uuid = UUID.randomUUID();
        //生成一个16位的UUID
        String id = uuid.toString().replace("-","").substring(0,16);
        Date date = new Date();
        History history = new History(id,username,goodId,date);
        Integer result = historyMapper.insertHistory(history);
        if (result > 0){
            return true;
        }
        return false;
    }
}
